import java.util.*;

public class Num2032 {
    public static void main(String[] args) {
        Num2032 num2032 = new Num2032();
        System.out.println(num2032.twoOutOfThree(new int[]{2,15,10,11,14,12,14,11,9,1},new int[]{8,9,13,2,11,8},new int[]{13,5,15,7,12,7,8,3,13,15}));
    }
    //[2,15,10,11,14,12,14,11,9,1]
    //[8,9,13,2,11,8]
    //[13,5,15,7,12,7,8,3,13,15]
    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        Arrays.sort(nums3);
        Map<Integer,Integer> map = new HashMap<>();
        for (int i : nums1) {
            map.put(i,1);
        }
        for (int i = 0; i < nums2.length; i++) {
            if (i == 0) {
                map.put(nums2[i], map.getOrDefault(nums2[i],0) + 1);
            }else {
                if (i < nums2.length && nums2[i] == nums2[i - 1]) continue;
                else map.put(nums2[i], map.getOrDefault(nums2[i],0) + 1);
            }
        }

        for (int i = 0; i < nums3.length; i++) {
            if (i == 0) {
                map.put(nums3[i], map.getOrDefault(nums3[i],0) + 1);
            }else {
                if (i < nums3.length && nums3[i] == nums3[i - 1]) continue;
                else map.put(nums3[i], map.getOrDefault(nums3[i],0) + 1);
            }
        }
        List<Integer> list = new ArrayList<>();
        for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
            if (entry.getValue() > 1) list.add(entry.getKey());
        }
        return list;
    }
}
